package com.asset.salesforce.service;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.springframework.stereotype.Service;


@Service
public class ImportLeadUtils {
		
	public Boolean checkDateInFormDayMonthYear(final String date) {
	
		final String DATE_PATTERN = "(0?[1-9]|[12][0-9]|3[01])/(0?[1-9]|1[012])/((19|20)\\d\\d)";
		Pattern pattern = Pattern.compile(DATE_PATTERN);
		Matcher matcher = pattern.matcher(date);
		if(matcher.matches()){
			 matcher.reset();
			 return true;
			 
		}else{
			return false;
		}
	}
	public Boolean checkDateInFormMonthDayYear(final String date) {
		
		final String DATE_PATTERN = "((0?[1-9]|1[012])/0?[1-9]|[12][0-9]|3[01])/((19|20)\\d\\d)";
		Pattern pattern = Pattern.compile(DATE_PATTERN);
		Matcher matcher = pattern.matcher(date);
		if(matcher.matches()){
			 matcher.reset();
			 return true;
			 
		}else{
			return false;
		}
	}
public Boolean checkDateInFormDayMonthYearDashes(final String date) {
		
		final String DATE_PATTERN = "(0?[1-9]|[12][0-9]|3[01])-(0?[1-9]|1[012])-((19|20)\\d\\d)";
		Pattern pattern = Pattern.compile(DATE_PATTERN);
		Matcher matcher = pattern.matcher(date);
		if(matcher.matches()){
			 matcher.reset();
			 return true;
			 
		}else{
			return false;
		}
	}
public Boolean checkDateInFormMonthDayYearDashes(final String date) {
	
	final String DATE_PATTERN = "(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])-((19|20)\\d\\d)";
	Pattern pattern = Pattern.compile(DATE_PATTERN);
	Matcher matcher = pattern.matcher(date);
	if(matcher.matches()){
		 matcher.reset();
		 return true;
		 
	}else{
		return false;
	}
}
	public Date dateInFormDayMonthYear(final String date) {
		
		DateFormat format = new SimpleDateFormat("dd/MM/yyyy");
		Date date2;
		try {
			date2 = format.parse(date);
			return date2;
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
		
	}
public Date dateInFormMonthDayYear(final String date) {
		
		DateFormat format = new SimpleDateFormat("MM/dd/yyyy");
		Date date2;
		try {
			date2 = format.parse(date);
			return date2;
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
		
	}
	public Date dateInFormDayMonthYearDashes(final String date) {
			
			DateFormat format = new SimpleDateFormat("dd-MM-yyyy");
			Date date2;
			try {
				date2 = format.parse(date);
				return date2;
			} catch (ParseException e) {
				e.printStackTrace();
				return null;
			}
			
		}
	public Date dateInFormMonthDayYearDashes(final String date) {
		
		DateFormat format = new SimpleDateFormat("MM-dd-yyyy");
		Date date2;
		try {
			date2 = format.parse(date);
			return date2;
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
		
	}
	public Boolean checkCompititorOffer(String string) {
		if(string.equals("")){
			return false;
		}
		String [] strings=string.split(" ");
		for (int i = 0; i < strings.length; i++) {
			if(strings[i].equals("N/A")|| strings[i].contains("no")|| strings[i].contains("No")){
				return false;
			}
		}
		return true;
	}
	public String[] splitNameFromSheet(String string) {
		String [] strArr= new String[2];
		if(string != null && !string.equalsIgnoreCase("") ){
			String [] strTempArr  =string.split(" ");
			if(strTempArr.length == 1){
				strArr[0] = strTempArr[0];
				strArr[1] = "";
			}
			else if(strTempArr.length == 2){
				strArr[0] = strTempArr[0];
				strArr[1] = strTempArr[1];

			}
			else if(strTempArr.length == 3){
				strArr[0] = strTempArr[0]+strTempArr[1];
				strArr[1] = strTempArr[2];
			}

			else if(strTempArr.length == 4){
				strArr[0] = strTempArr[0]+strTempArr[1];
				strArr[1] = strTempArr[2]+strTempArr[3];
			}

			else if(strTempArr.length == 5){
				strArr[0] = strTempArr[0]+strTempArr[1]+strTempArr[2];
				strArr[1] = strTempArr[3]+strTempArr[4];
			}else{
				String temp = new String("");
					for(int i =0;i<strTempArr.length/2;i++){
						temp+= strTempArr[i];
					}
					strArr[0] =temp;
					temp="";
					for(int i =strTempArr.length/2;i<strTempArr.length;i++){
						temp+= strTempArr[i];
					}
					strArr[1] =temp;
					
			}
			return strArr;
		}else{
			strArr[0] = "(Not specified First Name)";
			strArr[1] = "(Not specified Last Name)";
			return strArr;
		}
		

		//System.out.println("<><><><><><><><><><><><<><><><><><"+strTempArr.length);
		
		
	}

}
